import uuid

from sqlalchemy import Column, Integer, String, Text, ForeignKey,Boolean
from sqlalchemy.dialects.mysql import MEDIUMTEXT
from sqlalchemy.orm import relationship
from Model.default import Base


class Commontext(Base):
    __tablename__ = 'common_text'
    id = Column(Integer, primary_key=True)
    kind = Column(String(10))
    title = Column(String(50))
    sketch = Column(Text)
    text = Column(Text)
    date = Column(String(50))
    author = Column(Integer)
    username = Column(String(20))
    reads = Column(Integer, default=0)
    pushes = Column(Integer, default=0)
    thumbs = Column(Integer, default=0)
    collects = Column(Integer, default=0)
    index_image = Column(MEDIUMTEXT)
    resource = Column(String(10), default=0)
    tips = Column(String(50), default=0)
    visibility = Column(String(10), default='all')
    issift = Column(Integer, default=0)
    reply_count=Column(Integer, default=0)
    active=Column(Boolean, default=True)


    def to_dict(self):
        return {col.name: getattr(self, col.name, None) for col in self.__table__.columns}




# 采用分级评论,二级评论采取双方信息措施
# uuid只作为唯一标记无实际意义
# 只允许上传一张图片一次,格式为base64
class first_CommonComment(Base):
    __tablename__ = 'f_common_comments'
    uuid=Column(String(30), primary_key=True)
    id = Column(Integer)
    author = Column(Integer)
    date = Column(String(50))
    image = Column(MEDIUMTEXT)
    content=Column(Text)
    reply_count = Column(Integer, default=0)
    like_count = Column(Integer, default=0)
    # 实际处理后这个author是多余的
    user_keyidf= Column(Integer, ForeignKey('user.id'))
    user_key = relationship("user", back_populates="public_info_fcomment")

    def to_dict(self):
        # 包括所有字段即使它们未被赋值
        return {col.name: getattr(self, col.name, None) for col in self.__table__.columns}


class second_CommonComment(Base):
    __tablename__ = 's_common_comments'
    uuid = Column(String(30), primary_key=True)
    id = Column(Integer)
    date = Column(String(50))
    f_author = Column(Integer)
    author = Column(Integer)
    image = Column(MEDIUMTEXT)
    content = Column(Text)
    f_uuid=Column(String(30), ForeignKey('f_common_comments.uuid'))

    double_two=Column(Integer, default=0)
    # 用于判断是否是二级之间的回复

    like_count = Column(Integer, default=0)
    # 实际处理后这个author是多余的
    user_keyids = Column(Integer, ForeignKey('user.id'))
    user_key = relationship("user", back_populates="public_info_scomment")

    def to_dict(self):
        # 包括所有字段即使它们未被赋值
        return {col.name: getattr(self, col.name, None) for col in self.__table__.columns}


